<?php
/**
 * @notes:
 * @return
 * @author: admin
 * @date: 2024/9/10
 */


namespace addons\shopro\service\lucky;


use app\admin\model\shopro\lucky\User;

class UserService
{


    protected $query = null;
    protected $format = null;

    public function __construct(\Closure $format = null, \think\db\Query $query = null)
    {
        $this->query = $query ?: new User();
        $this->relationSearch = true;
        $this->format = $format;
    }


    public function getList($params,$user)
    {
        if(!$user){
            error_stop('用户不存在！');
        }
        $where=[];
        switch ($params['type']){
            case 1:
                $where=[
                    'user.stutas'=>'0'
                ];
                break;
            case 2:
                $where=[
                    'user.stutas'=>'1'
                ];
                break;
        }
        $list = $this->query->with(['goods','server'])->where(['user.user_id'=>$user['id']])->where($where)->order('user.createtime','DESC')->paginate(request()->param('list_rows', 10));

        foreach ($list as $row) {
            $row->visible(['lucky_id','commission','score','number','p_number','total_price','p_total_price','proportion','stutas','createtime']);
            $row->visible(['goods']);
            $row->getRelation('goods')->visible(['title','image']);
            $row->visible(['server']);
            $row->getRelation('server')->visible(['open_lucky_time','name']);
        }

        return $list;

    }

}